function bodyKeyToString(object) {
  return Object.keys(object).join(',');
}

function bodyValueToString(object) {
  return Object.values(object)
    .map((x) => (typeof x === 'number' ? x : `'${x}'`))
    .join(',');
}

function insertSql(table, body) {
  return `insert into ${table}(${bodyKeyToString(
    body,
  )}) VALUES(${bodyValueToString(body)})`;
}

function updateSql(table, id, body) {
  return `update ${table} set ${Object.entries(body)
    .map(([k, v]) => `${k}=${typeof v === 'number' ? v : `'${v}'`}`)
    .join(',')} where id=${id}`;
}

function deleteSql(table, id) {
  return `delete from ${table} where id=${id}`;
}

module.exports = {
  bodyKeyToString,
  bodyValueToString,
  insertSql,
  updateSql,
  deleteSql,
};
